package com.web_bloks.content.client;

import java.util.HashMap;

import com.web_bloks.system.client.Logger;

/**
 * Usage: sub-class and use the 'add' method
 * to add pages to the list
 * 
 * @author Jean-Lou Dupont
 *
 */
/*
	final static class PagesList extends ContentPages {
		
		protected void initList() {
			add( (ContentPage) GWT.create(MainPage.class) );
			add( (ContentPage) GWT.create(AboutPage.class) );
			add( (ContentPage) GWT.create(ConfigPage.class) );
			add( (ContentPage) GWT.create(ConfigTestPage.class) );
		}
	}
 */
/**
 * @deprecated
 */
abstract public class ContentPages {

	static HashMap<String,ContentPage> list = new HashMap<String,ContentPage>();
	
	/**
	 * Adds a ContentPage instance
	 * 
	 * @param p ContentPage
	 */
	protected void add(ContentPage p) {
		Logger.logInfo(this.getClass()+".add: adding name["+p.getPageName()+"]");
		list.put(p.getPageName(), p);
	}
	
	/**
	 * Used to retrieve a ContentPage by name
	 * 
	 * @param name
	 * @return
	 */
	public ContentPage get(String name) {
	
		ContentPage cp = null;
		
		if ( list.containsKey(name)) 
			cp = list.get(name);

		Logger.logInfo(this.getClass()+".get: name["+name+"] result["+(cp!=null)+"]");
		
		return cp;
	}

	/**
	 * @override
	 */
	abstract protected void initList();
}
